<template>
  <div>
    <el-dialog
      title="处方列表"
      append-to-body
      :visible.sync="dialogVisible"
      width="92%"
      class="dialog"
      v-loading="loading"
      element-loading-background="rgba(0, 0, 0, 0.8)"
      :before-close="handleClose"
      :close-on-click-modal="false"
      center
    >
      <div class="container">
        <!--   <baleTable :tableData="tableData" :tableHead="tableHead" :isSearch="true" :tableLoading="tableLoading"
          :page="page" @pageSizeChange="pageSizeChange" @handleCurrentChange="handleCurrentChange"
          @searchMethods="searchMethods" @tableSortChange="tableSortChange" ref="baleTable">
          <template #headLeft>
          </template>
          <template #name="{ scope }">
            {{scope.row.patient.name}}
          </template>
          <template #review_result="{ scope }">
            {{scope.row.review_result=='1'?'通过':'不通过'}}
          </template>

          <template #second_review_result="{ scope }">
            {{scope.row.second_review_result=='1'?'通过':'不通过'}}
          </template>

          <template #medical="{ scope }">
            <div class="mt5" v-for="item in JSON.parse(scope.row.medical)" :key="item.id">
              <el-popover trigger="hover" placement="top">
                <p>单价: {{item.price }}</p>
                <p>药品规格: {{item.size }}</p>
                <p>频率(次): {{item.doseFrequency }}</p>
                <p>用药天数(天): {{item.days }}</p>
                <p>用法: {{item.guide }}</p>
                <p>注意事项: {{item.precautions }}</p>
                <div slot="reference" class="name-wrapper">
                  <div>
                    <el-tag size="medium">{{ item.name }}</el-tag>
                  </div>
                </div>
              </el-popover>
            </div>
          </template>
          <template #caozuo="{ scope }">
            <el-button type="primary" size="mini" @click="showDialog(scope.row)">撤回处方</el-button>
          </template>
        </baleTable> -->
        <el-table
          v-loading="loading"
          :data="tableData"
          height="500px"
          border
          style="width: 100%"
        >
          <el-table-column prop="name" align="center" label="就诊人">
            <template slot-scope="scope">
              {{ scope.row.patient.name }}
            </template>
          </el-table-column>
          <el-table-column
            prop="medical"
            align="center"
            label="药品信息"
            width="180"
          >
            <template slot-scope="scope">
              <div
                class="mt5"
                v-for="item in JSON.parse(scope.row.medical)"
                :key="item.id"
              >
                <el-popover trigger="hover" placement="top">
                  <p>单价: {{ item.price }}</p>
                  <p>药品规格: {{ item.size }}</p>
                  <!--   <p>频率(次): {{ item.doseFrequency }}</p>
                  <p>用药天数(天): {{ item.days }}</p> -->
                  <p>剂量: {{ item.dosage }}</p>
                  <!--            <p>注意事项: {{ item.precautions }}</p> -->
                  <div slot="reference" class="name-wrapper">
                    <div>
                      <el-tag size="medium">{{ item.name }}</el-tag>
                    </div>
                  </div>
                </el-popover>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="status" align="center" label="单据状态">
          </el-table-column>
          <el-table-column prop="main" align="center" label="患者主诉">
          </el-table-column>
          <!--  <el-table-column prop="review_name" align="center" label="初审人">
          </el-table-column>
          <el-table-column prop="review_result" label="初审结果">
            <template slot-scope="scope">
              {{scope.row.review_result=='1'?'通过':'不通过'}}
            </template>
          </el-table-column>
          <el-table-column prop="second_review_name" align="center" label="复审人">
          </el-table-column>
          <el-table-column prop="second_review_result" align="center" label="复审结果">
            <template slot-scope="scope">
              {{scope.row.second_review_result=='1'?'通过':'不通过'}}
            </template>
          </el-table-column> -->
          <el-table-column prop="review_name" align="center" label="操作">
            <template slot-scope="scope">
              <el-button
                :disabled="scope.row.status == '已撤回'"
                type="primary"
                size="small"
                @click="rePrescrip(scope.row.id)"
                >撤回处方</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { tableHead } from "../config";
import { ApiAdminAdviceList, ApiAdviceRollback } from "../../../api/index";
export default {
  data() {
    return {
      tableHead,
      tableLoading: false,
      dialogVisible: false,
      page: {
        page: 1,
        size: 25,
        total: 0,
      },
      tableData: [],
      loading: true,
    };
  },

  methods: {
    handleClose() {
      this.dialogVisible = false;
    },
    show(row) {
      this.dialogVisible = true;
      this.order_id = row.id;
      this.getTableData();
    },
    getTableData() {
      this.tableLoading = true;
      ApiAdminAdviceList({ ...this.page, order_id: this.order_id }).then(
        (res) => {
          let { data, page } = res;
          this.tableData = data;
          this.page.total = page.total;
          this.tableLoading = false;
          this.loading = false;
        }
      );
    },
    rePrescrip(id) {
      this.$confirm("是否确认撤回处方?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        center: true,
        type: "warning",
      })
        .then((res) => {
          ApiAdviceRollback(id).then((res) => {
            this.$message({
              type: "success",
              message: "撤回成功!",
            });
            this.getTableData();
          });
        })
        .catch((err) => {});
    },
  },
};
</script>

<style>
</style>